package edu.neusoft.yuejian_09.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.bean.Question;
import it.sephiroth.android.library.picasso.Picasso;

import static edu.neusoft.yuejian_09.base.Constant.PHOTO_URL;

/**
 * Created by 爽 on 2017/10/25.
 */

public class MasterQuestionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public MasterQuestionAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Question entity = (Question) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.u_name.setText(entity.getUser_name());
        viewHolder.u_question.setText(entity.getQa_question());
        viewHolder.m_answer.setText(entity.getQa_answer());
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_masterquestion, parent, false);
        return new ViewHolder(v);

    }

    //自定义的V
    public class ViewHolder extends RecyclerView.ViewHolder{

        TextView u_name,u_question,m_answer;

        public ViewHolder(View itemView) {
            super(itemView);
            u_name = (TextView) itemView.findViewById(R.id.username);
            u_question= (TextView) itemView.findViewById(R.id.question);
            m_answer= (TextView) itemView.findViewById(R.id.answer);
        }
    }

}
